package AliDiepPR.hWriting;

import java.io.*;
import android.app.*;
import android.graphics.*;
import android.os.Bundle;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import java.util.*;

import AliDiepPR.ANN.*;
import AliDiepPR.hWriting.R;

public class ZWriteActivity extends Activity {

	WriteView writeView;
	Button getImage;
	TextView result;
	Network network;
	Bitmap image;
	double[] input;
	double[] output;

	private String[] charArray = new String[] { "A", "Ă", "Â", "B", "C", "D",
			"�?", "E", "Ê", "G", "H", "K", "I", "L", "M", "N", "O",
			"Ô", "Ơ", "P", "Q", "R", "S", "T", "U", "Ư", "V", "X", "Y"};
	
	private List<String> charset;

	private void init() {
		charset = Arrays.asList(charArray);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		init();
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
/*		
		try {
			network = new Network(getResources().openRawResource(R.raw.netconfig));
		} catch (IOException e) {
			e.printStackTrace();
		}
		writeView = (WriteView) findViewById(R.id.writeView);
		writeView.setDrawingCacheEnabled(true);
		getImage = (Button) findViewById(R.id.btnGetImage);
		result = (TextView) findViewById(R.id.tvResult);

		getImage.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				image = writeView.getImage();
				input = Util.flattenIntMatrix(ImageTransformer.getScaledImage(
						8, 8, ImageTransformer
								.getMinimalImageMatrix(getBinaryImage(image))));
				output = network.use(input);
				int pos = Util.getPositionFromResult(output);
				result.setText(charset.get(pos));
				writeView.resetView();
			}
		});
		*/
	}

	private int[][] getBinaryImage(Bitmap bitmap) {
		int width = bitmap.getWidth();
		int height = bitmap.getHeight();
		int[][] result = new int[height][width];
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				int temp = bitmap.getPixel(j, i);
				if (temp == Color.WHITE) {
					result[i][j] = -1;
				} else {
					result[i][j] = 1;
				}
			}
		}
		return result;
	}
}